<template>
  <div class="permission-container">
    <div class="app-container">
      <!-- 表格 -->
      <el-card>
        <el-tabs>
          <!-- 左侧 -->
          <el-tab-pane label="建议管理">
            <el-table row-key="id" :data="list" border>
              <el-table-column label="序号" prop="name">
                <template #default="{ row }">
                  {{ row.id }}
                </template>
              </el-table-column>
              <el-table-column label="标题" prop="title" />
              <el-table-column label="建议内容" prop="content" />
              <el-table-column label="附带图片" prop="imgUrl" />
              <el-table-column label="提交建议的时间" prop="creatTime" />
              <el-table-column label="操作" fixed="right">
                <template slot-scope="scope">
                  <el-button
                    size="small"
                    type="primary"
                    @click="handleAnswer(scope.row.id)"
                    >回复</el-button
                  >
                  <el-button
                    size="small"
                    type="danger"
                    @click="handleDelete(scope.row.id)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </el-card>
      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <span>确定删除吗？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="deleteComfirm">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 弹框 -->
      <!-- <el-dialog :title="showTitle" :visible="showDialog" @close="closeDialog">
        <el-form v-loading="loading" label-width="90px">
          <el-form-item label="账号id" prop="id">
            <el-input v-model="formData.id" placeholder="请输入" disabled />
          </el-form-item>
          <el-form-item label="用户名" prop="username">
            <el-input v-model="formData.username" placeholder="请输入" />
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="formData.password" placeholder="请输入" />
          </el-form-item>
        </el-form>

        <template #footer>
          <div style="text-align: right">
            <el-button @click="closeDialog">取消</el-button>
            <el-button type="primary" @click="clickSubmit">确认</el-button>
          </div>
        </template>
      </el-dialog> -->

      <!-- 回复框 -->
      <el-dialog title="回复内容" :visible="smallDialog" @close="closeDialog">
        <el-form :model="formData">
          <el-form-item>
            <el-input v-model="formData.reply"></el-input>
          </el-form-item>
        </el-form>
        <template #footer>
          <div style="text-align: right">
            <el-button @click="closeDialog">取消</el-button>
            <el-button type="primary" @click="clickSubmit">确认</el-button>
          </div>
        </template>
      </el-dialog>
    </div>

    <!-- 分页 -->
    <div align="center">
      <el-pagination
        :current-page.sync="currentPage"
        layout="prev, pager, next, jumper"
        :total="list.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import {selectSuggest,deleteSuggest} from '@/api/role'
export default {
  name: 'Permission',
  data() {
    return {
      dialogVisible: false,
      // 分页数据
      currentPage: 1,
      list: [],
      showDialog: false,
      smallDialog:false,
      formData: {
        // enVisible: '0', // 0不开启, 1开启 (注意: 不是布尔值, 所以将来需要处理switch)
        username: '', // 名称
        password:'',
        reply: '' //内容
      },
      loading: false,
      permissionData: [] // 存放用于展示的权限列表数据 (树形结构)
    }
  },

  mounted() {
    console.log('进入页面的钩子函数')
    this.getPermissionList()
  },
  methods: {
    async getPermissionList() {

      const data = await selectSuggest()
      this.list = data
    },

    // 删除功能
    handleDelete(id) {
      this.deleteId = id
      this.dialogVisible = true
    },
    async deleteComfirm() {
      this.dialogVisible = false
      await deleteSuggest({
        id: this.deleteId
      })
      this.$message({
        message: '删除成功',
        type: 'success'
      })
      this.getPermissionList()
    },
    handleEdit(row){
      console.log(row)
      // const {postalCode,...formData} = row
      // formData.postalcode = postalCode
      this.formData = row;
      this.formData.postalcode = row.postalCode
      this.showDialog = true
    },

    handleAnswer() {
        this.smallDialog = true
    },
    closeDialog() {
        this.smallDialog = false
        this.formData = {
            reply: ''
        }
    },
    // 确认回复
    clickSubmit(){},

    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
    }
  }
}
</script>

<style>
</style>
